package fun.xinnix.handle;

import cn.hutool.json.JSONUtil;
import fun.xinnix.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class Consumer {
    @KafkaListener(topics = {"test", "test2"})
    public void handle(String message) {
        log.info("consumer-message:{}", message);
    }

    @KafkaListener(topics = "user")
    public void receive(ConsumerRecord<?, ?> record) {
        User value = JSONUtil.toBean(record.value().toString(), User.class);
        log.info("kafkaListener:{}, {}", record.key(), value);
    }
}
